

package com.bolt.support.desensitization.desensitizer;


import com.bolt.support.desensitization.annotation.ChineseNameSensitive;

/**
 * 中文名称脱敏器
 */
public class ChineseNameDesensitizer extends AbstractCharSequenceDesensitizer<String, ChineseNameSensitive> {

    @Override
    public String desensitize(String target, ChineseNameSensitive annotation) {
        if (required(target, annotation.condition())) {
            if (target.length() == 2) {
                return String.valueOf(desensitize(target, "", 1, 0, annotation.placeholder()));
            } else if (target.length() > 2) {
                return String.valueOf(desensitize(target, "", 1, 1, annotation.placeholder()));
            } else {
                return target;
            }
        } else {
            return target;
        }

    }

}
